// this is an example of working with arrays, using loops
// also it shows how loop commands Continue and Break work

DEFINE MISSIONS 0
DEFINE EXTERNAL_SCRIPTS -1 // Use -1 to not write AAA script
DEFINE UNKNOWN_EMPTY_SEGMENT 0
DEFINE UNKNOWN_THREADS_MEMORY 0

// --------------------
// THE STRIPPED MAIN THREAD
// contains initial info
// --------------------
thread 'MAIN'
 var
  $PLAYER_CHAR : Player
 end
01F0: set_max_wanted_level_to 6 
set_wb_check_to 0 
00C0: set_current_time 8 0 
04E4: unknown_refresh_game_renderer_at 2488.5601 -1666.84 
Camera.SetAtPos(2488.5601, -1666.84, 13.38)
$PLAYER_CHAR = Player.Create(#NULL, 2488.5601, -1666.84, 13.38)
$PLAYER_ACTOR = Actor.EmulateFromPlayer($PLAYER_CHAR)
Camera.SetBehindPlayer
set_weather 0          
wait 0                                   
$PLAYER_CHAR.SetClothes("PLAYER_FACE", "HEAD", Head)
$PLAYER_CHAR.SetClothes("JEANSDENIM", "JEANS", Legs)
$PLAYER_CHAR.SetClothes("SNEAKERBINCBLK", "SNEAKER", Shoes)
$PLAYER_CHAR.SetClothes("VEST", "VEST", Torso)
$PLAYER_CHAR.Build
$PLAYER_CHAR.CanMove = True
fade 1 0                     
select_interior 0
016C: restart_if_wasted at 2027.77 -1420.52 15.99 angle 137.0 unknown 0 
016D: restart_if_busted at 1550.68 -1675.49 14.51 angle 90.0 unknown 0 
create_thread @example01 
end_thread 

//=====================================================================
// example #1
//=====================================================================
:example01
thread "example01" 

 var 
  $num: Integer = 10 // actors number
  $actor: array 10 of Actor
  $marker: array 10 of marker
  $X: Float
  $Y: Float  
 end                      

// load needed model
#WMOPJ.Load

while not #WMOPJ.Available
 wait 0
end

wait 0
// start point, position of the first actor 
Actor.StorePos($PLAYER_ACTOR, $x, $y, $z)
inc($y,2)
dec($x,3)

FOR $CurrentIndex = 0 TO $num
 inc($x) // offset
 $actor[$CurrentIndex].Create(CivMale, #WMOPJ,  $x, $y, $z)     // create actor
 $marker[$CurrentIndex].CreateAboveActor($actor[$CurrentIndex]) // with marker above
 wait 250
end 

#WMOPJ.Destroy // we don't need it anymore
wait 1000

FOR $CurrentIndex = 0 TO $num   // destroy all actors and markers
  $marker[$CurrentIndex].Disable
  wait 250

  if $CurrentIndex <> 4 
  then 
    $actor[$CurrentIndex].DestroyWithFade
  else 
    Continue // skip the fifth actor, let him live ;)
  end
  
  if $CurrentIndex == 8
    then Break    // if it is the ninth actor then break the loop
  end
end

end_thread